import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'

export function useLazyData(apiFn: () => void) {
    // #1
    const target = ref(null)
    const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
        // #2
        if (isIntersecting) {
            stop()
            apiFn()
        }
    })
    // #3
    return target
}